package com.example.beikeyigou.setting;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.beikeyigou.R;
import com.example.beikeyigou.login_reg.UserBean;
import com.example.beikeyigou.utils.SaveUserUtils;
import com.example.beikeyigou.utils.URLUtils;

import java.util.HashMap;
import java.util.Map;

public class NewQuesActivity extends AppCompatActivity {
    private EditText pwdEt, newQuesEt, newAnswerEt;
    private TextView forgetTv;
    private Button confirmBtn;
    private ImageView backImg;

    UserBean.DataBean userData, newUserData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_ques);

        findView();
        refreshData();
        setListener();
        changeStatusBarTextImgColor(true);
    }

    public void changeStatusBarTextImgColor(boolean color) {
        if (color) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//实现状态栏图标和文字颜色为暗色
        } else {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);//恢复状态栏白色字体
        }
    }

    private void setListener() {
        confirmBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String pwd = pwdEt.getText().toString();
                String newQuestion = newQuesEt.getText().toString();
                String newAnswer = newAnswerEt.getText().toString();
                /**
                 * 暂无该功能接口
                 */
            }
        });
    }

    private boolean judgeInput(String pwd, String newQuestion, String newAnswer) {
        if (TextUtils.isEmpty(pwd)||TextUtils.isEmpty(newQuestion)||TextUtils.isEmpty(newAnswer)) {
            Toast.makeText(this, "输入内容不能为空！", Toast.LENGTH_SHORT).show();
            return false;
        };
        // 判断旧密码是否正确
        if (!pwd.equals(userData.getPassword())) {
            Toast.makeText(this, "旧密码输入不正确！", Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    private void refreshData() {
        userData = SaveUserUtils.getUserData(this);
        newUserData = new UserBean.DataBean(userData.getId(), userData.getPhone(),
                userData.getPassword(), userData.getName(), userData.getAddress(),
                userData.getNickname(), userData.getQuestion(), userData.getAnswer());
        if (userData == null) {
            Toast.makeText(this, "请先登录", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    private void findView() {
        pwdEt = findViewById(R.id.quesChange_Pwd);
        newQuesEt = findViewById(R.id.quesChange_question);
        newAnswerEt = findViewById(R.id.quesChange_answer);
        forgetTv = findViewById(R.id.quesChange_forget);
        confirmBtn = findViewById(R.id.quesChange_btn);
        backImg = findViewById(R.id.quesChange_back);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }
}